package com.enjoyor.soa.traffic.rest.tsms.dubbo.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.dto.tsms.ExecuteTaskDispatchDto;
import com.enjoyor.soa.traffic.api.dto.tsms.RltRouteDeviceDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboExecuteTaskDispatchService;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboRltRouteDeviceService;
import com.enjoyor.soa.traffic.api.videoms.dto.VideoStatusDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IMessageForIndexConsumeService;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.invoke.DubboVideoInfoServiceInvoke;
import com.enjoyor.soa.traffic.rest.tsms.helper.CheckPojoHelper;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
@Component
public class MessageForIndexConsumeService implements IMessageForIndexConsumeService{
	
	@Reference(version = "1.0.0", timeout = 10000)
	private IDubboRltRouteDeviceService iDubboRltRouteDeviceService;//关联设备dubbo；
	@Reference(version = "1.0.0", timeout = 10000)
	private IDubboExecuteTaskDispatchService iDubboExecuteTaskDispatchService;//派警dubbo接口
	@Autowired
	private DubboVideoInfoServiceInvoke videoInfoServiceInvoke;
	
	@SuppressWarnings("unchecked")
	@Override
	public ResultPojo getNumbersList(String executeTaskId,String routeId, String deptId) {
		// TODO Auto-generated method stub
		// 获取线路关联视频集合；
		List<RltRouteDeviceDto> listRltVideo = (List<RltRouteDeviceDto>) iDubboRltRouteDeviceService
				.getRltRouteDeviceList(null, null, routeId, null, null, "RLTDEVICETYPE01").getResultList();
		//关联视频总数
		int isVideoNum = listRltVideo.size();
		//关联视频正常数；
		int isAliableVideo = 0;
		ResultPojo videoStatusPojo = videoInfoServiceInvoke.getVideoStatusInfo();
		if(CheckPojoHelper.isValid(videoStatusPojo)) {
			List<VideoStatusDto> videoStatusList = (List<VideoStatusDto>)videoStatusPojo.getResultList();
			for(RltRouteDeviceDto rltVideoDto : listRltVideo) {
				String videoId = rltVideoDto.getDeviceId();
				for(VideoStatusDto videoStatusDto : videoStatusList) {
					if(videoId.equals(videoStatusDto.getVideoid()) && "1".equals(videoStatusDto.getStatus())) {
						isAliableVideo++;
						break;
					}
				}
			}
		}
		// 获取线路关联信号机集合；
		List<RltRouteDeviceDto> listRltSignal = (List<RltRouteDeviceDto>) iDubboRltRouteDeviceService
				.getRltRouteDeviceList(null, null, routeId, null, null, "RLTDEVICETYPE02").getResultList();
		//关联信号机总数
		int isSignalNum = listRltSignal.size();
		//关联信号机正常数（暂时获取不到，默认全部在线）
		int isAliableSignal = isSignalNum;
		// 获取对应任务编号的派警List；
		ResultPojo resultPojo1 = iDubboExecuteTaskDispatchService.getExecuteTaskDispatchList(null, executeTaskId, null, null, null);
		List<ExecuteTaskDispatchDto> listExecuteTaskDispatch = (List<ExecuteTaskDispatchDto>) resultPojo1.getResultList();
		//配置警员总数
		int isPoliceNum = listExecuteTaskDispatch.size();
		//在线警员数量；
		int isAliablePolice = 0;
		Map<String, Object> numMap = new HashMap<>();
		numMap.put("isVideoNum",isVideoNum);
		numMap.put("isAliableVideo",isAliableVideo );
		numMap.put("isSignalNum", isSignalNum);
		numMap.put("isAliableSignal", isAliableSignal);
		numMap.put("isPoliceNum",isPoliceNum );
		numMap.put("isAliablePolice",isAliablePolice);
		//创建存放汇总数据List；
		List NumbersList = new ArrayList<>();
		NumbersList.add(numMap);
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultList(NumbersList);
		return resultPojo;
	}
	
}
